//
//  SecondCellOfCommend.m
//  FreeTravel
//
//  Created by 徐康 on 16/8/31.
//  Copyright © 2016年 KX. All rights reserved.
//

#import "SecondCellOfCommend.h"
#import "FreeTravelMacro.h"
@implementation SecondCellOfCommend

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.iconImageView = [[UIImageView alloc]init];
        self.coverImageView = [[UIImageView alloc]init];
        self.titleLabel = [[UILabel alloc]init];
        self.subjectLabel = [[UILabel alloc]init];
        self.grayView = [[UIView alloc]init];
        self.usernameLabel = [[UILabel alloc]init];
        self.picImageView = [[UIImageView alloc]init];
        self.columnLabel = [[UILabel alloc]init];
        [self.coverImageView addSubview:self.columnLabel];
        [self.contentView addSubview:self.usernameLabel];
        
        [self.contentView addSubview:self.grayView];
        [self.contentView addSubview:self.iconImageView];
        [self.contentView addSubview:self.coverImageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.subjectLabel];
        [self.contentView addSubview:self.picImageView];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.subjectLabel.textAlignment = NSTextAlignmentCenter;
    self.grayView.backgroundColor = [UIColor lightGrayColor];
    self.titleLabel.numberOfLines = 0;
    self.subjectLabel.numberOfLines = 0;
    self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    self.subjectLabel.font = [UIFont systemFontOfSize:13];
    self.columnLabel.backgroundColor = COLORFORFREETRAVEL;
    self.usernameLabel.font = [UIFont systemFontOfSize:13];
    self.columnLabel.textColor = [UIColor whiteColor];
    self.columnLabel.font = [UIFont systemFontOfSize:13];
    self.columnLabel.textAlignment = NSTextAlignmentCenter;
    self.picImageView.layer.cornerRadius = 25;
    self.picImageView.layer.masksToBounds = YES;
    [self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(200);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-20);
        make.height.mas_equalTo(50);
        make.top.equalTo(self.usernameLabel.mas_bottom).mas_offset(10);
    }];
    [self.subjectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
        make.left.equalTo(self.contentView.mas_left).mas_offset(10);
        make.bottom.equalTo(self.iconImageView.mas_top).mas_offset(-10);
    }];
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.bottom.equalTo(self.grayView.mas_top).mas_offset(-10);
        make.height.width.mas_equalTo(30);
    }];
    [self.grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(10);
    }];
    [self.columnLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(70);
        make.left.equalTo(self.coverImageView.mas_left);
        make.top.equalTo(self.coverImageView.mas_top).mas_offset(20);
    }];
    [self.picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.centerY.equalTo(self.coverImageView).multipliedBy(2);
        make.width.height.mas_offset(50);
    }];
    [self.usernameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.picImageView.mas_bottom).mas_offset(10);
        make.centerX.equalTo(self.contentView);
        make.height.mas_equalTo(10);
    }];
    
}
- (void)setModel:(ModelOfEntryCommend *)model{
    _model = model;
    self.titleLabel.text = model.title;
    self.subjectLabel.text = model.subject;
    self.usernameLabel.text = model.username;
    self.columnLabel.text = model.column;
    NSArray *array = [model.cover componentsSeparatedByString:@"/webp"];
    NSString *string1 = array.firstObject;
    NSString *string2 = array.lastObject;
    model.cover = [string1 stringByAppendingString:string2];
    
    _coverImageView.contentMode = UIViewContentModeScaleToFill;
    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:model.cover]];
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.icon_url]];
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:model.pic]];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
